//
//  ZHFPlaceItem.m
//  GoTraveling
//
//  Created by dllo on 15/12/23.
//  Copyright © 2015年 开发华佗. All rights reserved.
//

#import "ZHFPlaceItem.h"

#import "ZHFImageView.h"

#import "UIImageView+WebCache.m"

#import "ZHFPlace.h"

#import "StarView.h"

@interface ZHFPlaceItem ()

@property (nonatomic, retain) UIImageView *imageView;

@property (nonatomic, retain) UILabel *nameLable;

@property (nonatomic, retain) StarView *startView;

@property (nonatomic, retain) UILabel *rating_users;

@end

@implementation ZHFPlaceItem

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        [self createSubViews];
    }
    return self;
}

- (void)createSubViews {
    
    ZHFImageView *occupyImage = [[ZHFImageView alloc] initWithFrame:self.bounds];
    occupyImage.layer.cornerRadius = 5;
    occupyImage.layer.masksToBounds = YES;
    [self.contentView addSubview:occupyImage];
    
    self.imageView = [[UIImageView alloc] initWithFrame:self.bounds];
    self.imageView.contentMode = UIViewContentModeScaleAspectFill;
    self.imageView.layer.cornerRadius = 5;
    self.imageView.layer.masksToBounds = YES;
    [self.contentView addSubview:self.imageView];
    
    self.nameLable = [[UILabel alloc] initWithFrame:CGRectMake(10, self.frame.size.height - 20 - 30, self.frame.size.width - 20, 20)];
//    self.nameLable.backgroundColor = [UIColor magentaColor];
    self.nameLable.font = [UIFont systemFontOfSize:18 weight:0.2];
    self.nameLable.textColor = [UIColor whiteColor];
    [self.contentView addSubview:self.nameLable];
    
    self.startView = [[StarView alloc] initWithFrame:CGRectMake(10, self.frame.size.height - 20, self.frame.size.width / 2, 10) number:5];
    
    self.rating_users = [[UILabel alloc] initWithFrame:CGRectMake(self.frame.size.width / 2 + 25, self.startView.frame.origin.y, SCREEN_WIDTH / 2 - 20, 10)];
    self.rating_users.textColor = [UIColor whiteColor];
    self.rating_users.font = [UIFont systemFontOfSize:11];
    [self.contentView addSubview:self.rating_users];
}

- (void)setPlace:(ZHFPlace *)place
{
    [self.contentView addSubview:self.startView];
    [self.imageView sd_setImageWithURL:[NSURL URLWithString:place.image_url]];
    self.nameLable.text = place.name;
    NSInteger num = (NSInteger)[place.user_score floatValue];
    [self.startView setStarWithNumber:num];
    self.rating_users.text = [NSString stringWithFormat:@"%@分",place.user_score];
}

@end
